home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 2.6 KB | 87 lines | [TEXT/CWIE] |
- // ConstArrayOf.h
-
- #ifndef ConstArrayOf_h
- #define ConstArrayOf_h
-
- #ifndef Integers_h
- #include "Integers.h"
- #endif
- #ifndef Assert_h
- #include "Assert.h"
- #endif
- #ifndef Range_h
- #include "Range.h"
- #endif
-
- template < class Element >
- class ConstArrayOf
- {
- typedef ConstArrayOf< Element > ConstArrayType;
-
- private:
- const Element *start;
- uint32 length;
-
- public:
- ConstArrayOf()
- : start( 0 ),
- length( 0 )
- {}
-
- ConstArrayOf( const Element *theStart, uint32 theLength )
- : start( theStart ),
- length( theLength )
- { Assert( theStart != 0 || length == 0 ); }
-
- const Element *Start() const { return start; }
- const Element *End() const { return start + length; }
-
- uint32 Length() const { return length; }
- URange32 Range() const { return URange32( 0, Length() ); }
-
- uint32 BoundedLength( uint32 bound ) const
- { return ( length <= bound ) ? length : bound; }
-
- void LimitLength( uint32 limit ) { length = BoundedLength( limit ); }
-
- bool IsEmpty() const { return length == 0; }
- bool Null() const { return start == 0; }
-
- const Element& operator[]( uint32 i ) const { Assert( i < length ); return start[i]; }
-
- ConstArrayType Head( uint32 position ) const;
- ConstArrayType Tail( uint32 position ) const;
- ConstArrayType Middle( URange32 ) const;
-
- void Truncate( uint32 position ); // *this = Head( *this, position );
- void Shorten( uint32 amount ); // *this = Tail( *this, amount )
-
- void Append( ConstArrayType tail );
- void Prepend( ConstArrayType head );
-
- void operator+=( ConstArrayType tail ) { Append( tail ); }
- ConstArrayType operator+( ConstArrayType tail ) const;
-
- bool Precedes( ConstArrayType r ) const { return End() == r.start; }
- bool Follows( ConstArrayType r ) const { return start == r.End(); }
-
- bool IsHeadOf( ConstArrayType r ) const;
- bool IsTailOf( ConstArrayType r ) const;
-
- // These operators express the containment ordering
- bool operator==( ConstArrayType r ) const { return start == r.start && length == r.length; }
- bool operator!=( ConstArrayType r ) const { return start != r.start || length != r.length; }
- bool operator<=( ConstArrayType r ) const;
- bool operator>=( ConstArrayType r ) const { return r <= *this; }
- bool operator<( ConstArrayType r ) const;
- bool operator>( ConstArrayType r ) const { return r < *this; }
-
- bool Touches( ConstArrayType r ) const;
- ConstArrayType operator&( ConstArrayType r ) const;
- ConstArrayType operator|( ConstArrayType r ) const;
- void operator&=( ConstArrayType r ) { *this = *this & r; }
- void operator|=( ConstArrayType r ) { *this = *this | r; }
- };
-
- #endif
-